package Uti;

import java.util.Scanner;

public final class ScannerUti {

    static Scanner cin = new Scanner(System.in);

    private ScannerUti() {
    }


    public static int getInt() {

        while (true) {
            try {
                String s = cin.nextLine();
                if (!s.isEmpty())
                    return Integer.parseInt(s);
            } catch (NumberFormatException e) {
                error();
            }
        }

    }

    public static int getMonth() {
        while (true) {
            try {
                int Month = getInt();
                if (Month <= 12 && Month > 0) return Month;
                else error();
            } catch (NumberFormatException e) {
                error();
            }
        }
    }

    public static Double getDouble() {
        while (true) {
            try {
                String s = cin.nextLine();
                if (!s.isEmpty())
                    return Double.parseDouble(s);
            } catch (NumberFormatException e) {
                error();
            }
        }

    }

    public static Float getFloat() {
        while (true) {
            try {
                String s = cin.nextLine();
                if (!s.isEmpty()) return Float.parseFloat(s);
            } catch (NumberFormatException e) {
                error();
            }
        }

    }

    public static Byte getByte() {

            while (true) {
                try {
                    String s = cin.nextLine();
                    if (!s.isEmpty())
                        return Byte.parseByte(s);
                } catch (NumberFormatException e) {
                    error();
                }
            }


    }public static Integer getAge() {

            while (true) {
                try {
                    String s = cin.nextLine();
                    if (!s.isEmpty()){
                        int age = Integer.parseInt(s);
                        if(age<0||age>150)error();
                        else return age;
                    }

                } catch (NumberFormatException e) {
                    error();
                }


        }
    }

    public static String getSting() {
        while (true) {
            String s = cin.nextLine();
            if (!s.isEmpty()) return s;
        }
    }



    private static void error() {
        System.out.print("输入有误，请重新输入:");
    }

}
